<?php
/**
 * 糖果城堡
 */
namespace App\Repositories\Game\Castle;
use App\Models\GameDB\Castle\CastleExchangeLog as Model;
use App\Traits\Singleton;

class CastleExchangeLogRepositories
{
    use Singleton;
    public function swap(int $userId, int $count,$userCoin,$coin)
    {
        $balance = CastleUserRepositories::getInstance()->userBalance($userId);
        return Model::query()->create([
            "user_id" => $userId,
            "exchange"  => $count,
            "remain_gold"  => $userCoin - $coin,  // 用户金币吗  暂时未用
            "remain_candy" => $balance + $count,
            "coin" => $coin,
        ]);
    }

    public function draw(int $userId, int $count)
    {
        $balance = CastleUserRepositories::getInstance()->userBalance($userId);
        return  Model::query()->create([
            "user_id" => $userId,
            "exchange"  => $count,
            "remain_gold"  => 0,
            "remain_candy" => $balance - $count,
        ]);
    }

//    public function create(array $data)
//    {
//        $model = new Model();
//        $model->fill($data);
//        $model->save();
//        $model->refresh();
//        return $model;
//    }

}
